using System;
using System.Windows.Forms;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using TXLooker.WorkItemExtention.Core;

namespace TXLooker.WorkItemExtention.UI
{
    public partial class WorkItemTypePatternEditorForm : Form
    {
        public WorkItemTypePatternEditorForm()
        {
            InitializeComponent();

            this.m_witMapCtrl.SelectedNodeChanged += new EventHandler(OnSelectedNodeChanged);
        }

        protected override void OnLoad(EventArgs e)
        {
            this.CenterToScreen();
            base.OnLoad(e);
        }

        private void OnSelectedNodeChanged(object sender, EventArgs args)
        {
            WorkItemType witype = this.m_witMapCtrl.WorkItemType;
            bool bEnabled = (witype != null);
            this.m_htmlContentEditorCtrl.Enabled = bEnabled;
            if (!bEnabled) return;

            ContentPattern pattern = this.m_witMapCtrl.ProjectProvider.Settings[witype.Name];
            this.m_htmlContentEditorCtrl.BodyHtml = pattern.Pattern;
            this.m_htmlContentEditorCtrl.WorkItemType = witype;
        }

        private void click_btnSave(object sender, EventArgs e)
        {
            this.m_witMapCtrl.ProjectProvider.Settings[this.m_witMapCtrl.WorkItemType.Name].Pattern = this.m_htmlContentEditorCtrl.Content;
        }
    }
}